package com.agnes.phone.other;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;

public class PhoneIncomingrReceiver extends BroadcastReceiver {
    private Activity mContext;

    public PhoneIncomingrReceiver(Activity context){
        this.mContext = context;
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        // 弹来电电话号码对话框
        String action = intent.getAction();
        if (!TextUtils.isEmpty(action)){
            switch (action){
                case "com.agnes.phone":
                    String number = intent.getStringExtra("incomingPhone");
                    if (!TextUtils.isEmpty(number)) {
                        Log.e("PhoneIncomingrReceiver", "电话号码:" + number);
                        new AlertDialog.Builder(mContext)
                                .setTitle("来电拦截信息")
                                .setMessage("来电号码：" + number)
                                .setPositiveButton("确定", (dialog, which) -> dialog.dismiss())
                                .setCancelable(false)
                                .create()
                                .show();
                    }
                    break;
            }


        }
    }
}
